package com.promise.jokerdream.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.promise.jokerdream.ui.theme.AppColors
import com.promise.jokerdream.ui.theme.AppFontSizes
import com.promise.jokerdream.ui.theme.AppSpacing

/**
 * 通用应用Chip组件
 * 用于所有需要选择功能的场景
 */
@Composable
fun AppChip(
    text: String,
    isSelected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    showDeleteIcon: Boolean = false,
    onDeleteClick: (() -> Unit)? = null
) {
    Box(
        modifier = modifier
            .clickable(
                interactionSource = remember { MutableInteractionSource() },
                indication = null
            ) { onClick() }
            .clip(RoundedCornerShape(8.dp))
            .background(
                if (isSelected) 
                    AppColors.Selected.copy(alpha = 0.12f) // 选中背景色
                else AppColors.Gray100 // 未选中背景色
            )
    ) {
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(4.dp),
            modifier = Modifier.padding(
                horizontal = AppSpacing.componentMedium,
                vertical = AppSpacing.componentSmall
            )
        ) {
            Text(
                text = text,
                fontSize = AppFontSizes.mediumBody,
                color = if (isSelected) 
                    AppColors.Selected // 选中文案颜色
                else AppColors.TextSecondary, // 未选中文案颜色
            )
            
            if (isSelected && showDeleteIcon && onDeleteClick != null) {
                Text(
                    text = "×",
                    fontSize = AppFontSizes.mediumBody,
                    color = AppColors.Selected, // 选中删除按钮颜色
                    fontWeight = FontWeight.Bold,
                    modifier = Modifier.clickable(
                        interactionSource = remember { MutableInteractionSource() },
                        indication = null
                    ) { onDeleteClick() }
                )
            }
        }
    }
}
